/**
 * 详情对话框
 */
var StoragePutSingleInfoDlg = {
    data: {
    	positionNumber: "",
    }
};

layui.use(['form', 'admin', 'ax','laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;
    
    //选择生产日期后，填入批次 
    laydate.render({
    	elem:'#singleDateofmanufacture',
    	done: function(value, date, endDate){
      	    var detailedDate = value.replace(/[-]/g,"");//得到日期生成的值，如：2017-08-18,去除-
      	    $("#singleBatchnumber").val(detailedDate);
      	}
    });
    laydate.render({
    	elem:'#recommend'
    })

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/storagePutSingle/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('storagePutSingleForm', result.data);

    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/storagePutSingle/editItem", function (data) {
            Feng.success("更新成功！");
        	var Index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(Index);
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });
    
    //点击库位编号
    $("#positionNumber").click(function(){
        layer.open({
            type: 2,
            title: '选择库位',
            area: ['700px', '400px'],
            content: Feng.ctxPath + '/storagePutSingle/toChoiceposition?storageNumber='+$("#storageNumber").val(),
            end: function () {
                $("#positionNumber").val(StoragePutSingleInfoDlg.data.positionNumber);//库位编号
            }
        });
    });
    
    //输入大包数量
    $("#putBalenum").keyup(function(){
			var putBalenum = $("#putBalenum").val();//大包数量
			$("#putNum").val(putBalenum);//改变应入数量
    });
    
    //输入应入数量
    $("#putNum").keyup(function(){
		var putNum = $("#putNum").val();//应入数量
		$("#putBalenum").val(putNum);//改变大包数量
    });

    //返回按钮
    $("#backupPage").click(function () {
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    });

});